﻿using STHPMS1.DAL.D_Core;
using STHPMS1.ICore.I_DAL.Repository;
using STHPMS1.ICore.I_Entity.Stmpms1;
using System.Collections.Generic;
using System.Data;
using ServiceStack.OrmLite;
using System.Text;
using System.Data.SqlClient;
using System;
using System.Linq.Expressions;
using ServiceStack.OrmLite.SqlServer;

namespace STHPMS1.DAL.D_Repository
{
    public class Dn_Divi_PlanningRepository : DalBase, IDn_Divi_PlanningRepository
    {
        public void SaveAll(IDn_Divi_Planning[] planningList)
        {
            StringBuilder sql = new StringBuilder();
            foreach (IDn_Divi_Planning plan in planningList)
            {
                sql.AppendFormat(@"insert into DN_DIVI_PLANNING(Id ,Anni_Name ,Divi_Time ,Mainsegid,RoadnetId,Segid ,Rdwayid ,Segid_Main ,Beginmp ,Endmp ,Pqi ,Pci ,Pssi,Rqi,Sri,Rl,Modelgroup_Pci,Main_Year,Segid_Repdefl ,Segid_Elamod,Segid_Pcidr)
values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}','{16}','{17}',{18},{19},{20});", plan.Id, plan.Anni_Name, plan.Divi_Time, plan.Mainsegid, plan.RoadnetId, plan.Segid, plan.Rdwayid, plan.Segid_Main, plan.Beginmp, plan.Endmp, plan.Pqi, plan.Pci, plan.
Pssi, plan.Rqi, plan.Sri, plan.Rl, plan.Modelgroup_Pci, plan.Main_Year, plan.Segid_Repdefl, plan.Segid_Elamod, plan.Segid_Pcidr);
               
            }
            using (IDbConnection conn = Adapter.OpenDbConnection())
            {
                IDbTransaction tran = conn.BeginTransaction();
                try
                {
                    IDbCommand cmmd = conn.CreateCommand();
                    cmmd.Transaction = tran;
                    cmmd.CommandText = sql.ToString();
                    cmmd.ExecuteNonQuery();
                    tran.Commit();
                }
                catch (Exception ex)
                {
                    tran.Rollback();
                    throw ex;
                }
            }
        }
    }
}
